<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <!--[if lt IE 9]>
    <script type="text/javascript" src="lib/html5shiv.js"></script>
    <script type="text/javascript" src="lib/respond.min.js"></script>
    <![endif]-->
    <link rel="stylesheet" type="text/css" href="static/h-ui/css/H-ui.min.css"/>
    <link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/H-ui.admin.css"/>
    <link rel="stylesheet" type="text/css" href="lib/Hui-iconfont/1.0.8/iconfont.css"/>
    <link rel="stylesheet" type="text/css" href="static/h-ui.admin/skin/default/skin.css" id="skin"/>
    <link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/style.css"/>
    <!--[if IE 6]>
    <script type="text/javascript" src="lib/DD_belatedPNG_0.0.8a-min.js"></script>
    <script>DD_belatedPNG.fix('*');</script>
    <![endif]-->
    <title>服务与环境映射管理</title>
</head>
<body>
<nav class="breadcrumb">
    <i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 服务管理 <span class="c-gray en">&gt;</span>服务与环境映射<a
        class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px"
        href="javascript:location.replace(location.href);" title="刷新"><i class="Hui-iconfont">&#xe68f;</i></a></nav>

<div>
    <div style="margin-left:30px;margin-top:20px;">
        <!--<label style="margin-left:65px;">服务：</label><input type="text" name="servicekey" id="servicekey" placeholder=" 服务" style="width:12%" class="input-text">-->
        <label style="margin-left:65px;">服务：</label>
        <span class="select-box" style="width:12%">
                <select class="select" size="1" name="serviceKey" id="serviceKey">
                    <option value="">请选择</option>
                </select>
            </span>
        <!--<label style="margin-left:80px;">环境：</label><input type="text" name="envKey" id="envKey" placeholder=" 环境" style="width:12%" class="input-text">-->
        <label style="margin-left:80px;">环境：</label>
        <span class="select-box" style="width:12%">
                <select class="select" size="1" name="envKey" id="envKey">
                    <option value="" selected>请选择</option>
                </select>
            </span>
        <label style="margin-left:50px;">Host：</label><input type="text" name="hostInfo" id="hostInfo"
                                                             placeholder=" Host" style="width:12%" class="input-text">
    </div>
    <div style="margin-left:30px;margin-top:20px;">
        <label style="margin-left:50px;">数据库：</label><input type="text" name="dbInfo" id="dbInfo" placeholder=" 数据库信息"
                                                            style="width:12%" class="input-text">
        <label style="margin-left:50px;">SwaggerUrl：</label><input type="text" name="swaggerUrl" id="swaggerUrl"
                                                                   placeholder=" Swagger" style="width:12%"
                                                                   class="input-text">
        <button name="find" id="find" style="margin-left:98px;width:80px" class="btn btn-success" type="button"
                onclick="pageSkip(1)"><i class="Hui-iconfont">&#xe665;</i> 搜索
        </button>
        <button name="empty" id="empty" style="margin-left:10px;width:80px" class="btn btn-success" type="button"
                onclick="empty()"><i class="Hui-iconfont">&#xe665;</i> 清空
        </button>
    </div>
</div>
<div class="cl pd-5 bg-1 bk-gray mt-20">
        <span class="l"><a href="javascript:;" onclick="datadel()" class="btn btn-danger radius"><i
                class="Hui-iconfont">&#xe6e2;</i> 批量删除</a>
            <a class="btn btn-primary radius" onclick="tservicedetail_add('新增映射','tservicedetail-add.html','800','600')"
               href="javascript:;"><i class="Hui-iconfont">&#xe600;</i> 添加映射关系</a>
        </span>
    <span class="r">共有数据：<strong id="total">0</strong> 条</span>
</div>
<div id="DataTables_Table_0_wrapper" class="dataTables_wrapper no-footer">
    <table class="table table-border table-bordered table-bg table-hover table-sort" id="table">
        <thead>
        <tr class="text-c">
            <th width="5%"><input name="" type="checkbox" value=""></th>
            <th width="5%">ID</th>
            <th width="10%">服务</th>
            <th width="5%">环境</th>
            <th width="10%">Host</th>
            <th width="35%">数据库信息</th>
            <th width="20%">SwaggerUrl</th>
            <!--                <th width="15%">测试类</th>-->
            <th width="10%">操作</th>
        </tr>
        </thead>
        <tbody id="tuserList">
        </tbody>
    </table>
    <!--分页-->
    <div class="dataTables_info" id="dataTables_info">
        <span>共有 <strong id="totalPages"></strong> 页</span>
        <span>当前第 <strong id="now"></strong> 页</span>
    </div>
    <div class="dataTables_paginate paging_simple_numbers" id="pager">
    </div>
</div>
</div>
<script type="text/javascript" src="static/hry-auto/util.js"></script>
<script type="text/javascript" src="lib/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="lib/layer/2.4/layer.js"></script>
<script type="text/javascript" src="static/h-ui/js/H-ui.min.js"></script>
<script type="text/javascript" src="static/h-ui.admin/js/H-ui.admin.js"></script>
<script type="text/javascript" src="lib/My97DatePicker/4.8/WdatePicker.js"></script>
<script type="text/javascript">
    var layerIndex;
    //loading
    $(function () {
        $.ajaxSetup({
            layerIndex: -1,
            beforeSend: function () { //插件加载前
                layerIndex = layer.load(1, {shade: [0.01, '#fff']});
            },
            error: function () { //报错时执行
                layer.alert('显示异常，请刷新后重试', {
                    icon: 0,
                    skin: 'layer-ext-moon'
                });
            }
        });
    });

    function empty() {
        // $("#servicekey").val("");
        $("#serviceKey option:first").prop("selected", 'selected');
        $("#envKey option:first").prop("selected", 'selected');
        //$("#envKey").val("");
        $("#hostInfo").val("");
        $("#dbInfo").val("");
        $("#swaggerUrl").val("");
    }

    //查询用户列表
    $(document).ready(function () {
        var list = getServiceList();
        var serviceHtml = "";
        for (var i = 0; i < list.length; i++) {
            serviceHtml += "<option value=\"" + list[i].id + "\">" + list[i].servicekey + "</option>";
        }
        $("#serviceKey").append(serviceHtml);

        var envlist = getEnvList();
        var envhtml = "";
        for (var j = 0; j < envlist.length; j++) {
            envhtml += "<option value=\"" + envlist[j].id + "\">" + envlist[j].envkey + "</option>";
        }
        $("#envKey").append(envhtml);
        pageSkip(1);
    });

    //分页查询
    function pageSkip(index) {

        if (index == 0) {
            return;
        }
        var servicekey = $("#serviceKey").val();
        var envKey = $("#envKey").val();
        var hostInfo = $("#hostInfo").val();
        var dbInfo = $("#dbInfo").val();
        var swaggerUrl = $("#swaggerUrl").val();

        $.ajax({
            type: "post",
            url: "/tservicedetail/selectByCondition",
            data: {
                serviceid: servicekey,
                envid: envKey,
                hostinfo: hostInfo,
                dbinfo: dbInfo,
                swaggerurl: swaggerUrl,
                pageNum: index,
                pageSize: 10
            },
            dataType: "json",

            success: function (data) {
                var status = data.status;
                var msg = data.msg;

                console.log(data);
                var html = "";

                if (status == 0) {
                    var list = data.data.list;
                    $("#tuserList").html("");

                    for (var i = 0; i < list.length; i++) {
                        var row = list[i];
                        var dbInfo = row.dbinfo;
                        if (row.dbinfo == null) {
                            dbInfo = "";
                        } else {
                            try {
                                var dbInfoJson = JSON.stringify(JSON.parse(dbInfo), null, 2);
                                dbInfo = dbInfoJson;
                            } catch (e) {
                            }
                        }

                        var swaggerurl = row.swaggerurl == null ? "" : row.swaggerurl;


                        var rowHtml = "<tr class=\"text-c\">\n" +
                            "<td><input name=\"\" type=\"checkbox\" value=\"\"></td>\n" +
                            "<td>" + row.id + "</td>\n" +
                            "<td>" + row.servicekey + "</td>\n" +
                            "<td>" + row.envkey + "</td>\n" +
                            "<td>" + row.hostinfo + "</td>\n" +
                            "<td><pre style='text-align:left;border: 0px;padding: 0px;margin-bottom: 0px'>" + dbInfo + "</pre></td>\n" +
                            "<td>" + swaggerurl + "</td>\n" +
                            "<td class=\"f-14\"><a title=\"编辑\" href=\"javascript:;\" onclick=\"tservicedetail_edit('映射关系编辑','tservicedetail-edit.html'," + row.id + ",'800','600')\" style=\"text-decoration:none\"><i class=\"Hui-iconfont\">&#xe6df;</i></a> \n" +
                            "<a title=\"删除\" href=\"javascript:;\" onclick=\"tservicedetail_del(this," + row.id + ")\" class=\"ml-5\" style=\"text-decoration:none\"><i class=\"Hui-iconfont\">&#xe6e2;</i></a></td>\n" +
                            "</tr>";
                        html = html + rowHtml;
                    }
                    $("#tuserList").append(html);
                    pagination(data);
                    layer.close(layerIndex);

                } else {
                    layer.close(layerIndex);
                    layer.alert(msg, {
                        icon: 0,
                        skin: 'layer-ext-moon'
                    });
                }
            },


        });
    }

    /*映射关系-添加*/
    function tservicedetail_add(title, url, w, h) {
        layer_show(title, url, w, h);

    }

    /*映射关系-编辑*/
    function tservicedetail_edit(title, url, id, w, h) {
        url = url + "?id=" + id;
        layer_show(title, url, w, h);
    }

    /*删除*/
    function tservicedetail_del(obj, id) {
        var ms = "映射关系删除需谨慎，请确认是否删除！";
        del(obj, id, "/tservicedetail/deleteOne", ms);
    }

</script>
</body>
</html>